/**
 * This project create for studying propose at BUPT University. You can change or reuse this project anywhere
 */
package edu.bupt.ooad.library;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Hamed Abdollahpour
 */
public class BookDescription {
    
    private String title;
    
    private String author;
    
    private String category;
    
    private int isbn;
    
    private List<Book> books = new ArrayList<Book>();
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getAuthor() {
        return author;
    }
    
    public void setAuthor(String author) {
        this.author = author;
    }
    
    public void setCategory(String category) {
        this.category = category;
    }
    
    public String getCategory() {
        return category;
    }
    
    public int getIsbn() {
        return isbn;
    }
    
    public void setIsbn(int isbn) {
        this.isbn = isbn;
    }
    
    public boolean addBook(Book book) {
        return books.add(book);
    }
    
    public boolean removeBook(Book book) {
        return books.remove(book);
    }
    
    public Book createBook(int id) {
        Book book = new Book(this);
        book.setAvailable(true);
        book.setBookId(id);
        
        return book;
    }
    
    public List<Book> getBooks() {
        return books;
    }
    
    public Book getBook(int id) {
        for(Book book:books) {
            if(book.getBookId() == id) {
                return book;
            }
        }
        return null;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }

        return obj.hashCode() == hashCode();
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 71 * hash + (this.title != null ? this.title.hashCode() : 0);
        hash = 71 * hash + (this.author != null ? this.author.hashCode() : 0);
        hash = 71 * hash + (this.category != null ? this.category.hashCode() : 0);
        hash = 71 * hash + this.isbn;
        return hash;
    }

}
